"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

Replace this with more appropriate tests for your application.
"""

from django.test import TestCase

class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.assertEqual(1 + 1, 2)

from scrape_killersports import get_lines_table, game_rows, create_week_from_html
from urllib import URLopener
from bs4 import BeautifulSoup
from datetime import date
from pool_v2.models import Week, Game

class ScrapeTests(TestCase):
    def test_scraper(self):
        soup = BeautifulSoup(open('data_sources/lines_data_2012_11_11.htm'))
        table = get_lines_table(soup)
        self.assertEqual(soup.find_all('table')[7],table)
        self.assertEqual(len(game_rows(table)), 5)

    def test_create_week_from_html(self):
        soup = BeautifulSoup(open('data_sources/lines_data_2012_11_11.htm'))
        d = date(2012,11,11)
        create_week_from_html(soup,d)
        weeks = Week.objects.filter(date=d)
        self.assertEqual(len(weeks),1)
        self.assertEqual(len(Game.objects.filter(week=weeks[0])),5)
        
    def test_URL(self):
        opener = URLopener()
        soup = BeautifulSoup(opener.open('http://killersports.com/nba.py/query?sid=guest&text=date%3D%3D20121111&submit=query'))
        table = get_lines_table(soup)
        self.assertEqual(soup.find_all('table')[7],table)
        self.assertEqual(len(game_rows(table)), 5)

        




